package team.first.util;

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;

/**
 * @Author: HAPPY
 * @Project_name: project
 * @Package_name: team.first.util
 * @Date: 2021/12/3 11:17
 * @Description:
 */
public class DriverUtil {
    private static final String uri = "bolt://localhost:7687";
    private static final String username = "neo4j";
    private static final String password = "123456";

    public static Driver driver;

    static {
        driver =  GraphDatabase.driver(uri, AuthTokens.basic(username, password));
    }
    public static Driver getDriver() {
        return driver;
    }

    public static Session openSession() {
        return driver.session();
    }

    public static Session getNewSession() {
        return new GraphDatabase().driver(uri, AuthTokens.basic(username, password)).session();
    }

    public static void close(Session session) {
        session.close();
        driver.close();
    }
}
